
import { EntityCreateType } from '../const/ModelConst';
import AModelFmulaUtils from '../utils/AModelFmulaUtils';
export default class SPMerge implements IParamsMerge {
    constructor() {

    }

    merge(t: AIBasicParams, id: any) {
        if (!this.check(id)) {
            return;
        }


        this.initValue(t, "p_l_d1", t.BKDia);
        this.initValue(t, "p_r_d1", t.BKDia);

        this.initValue(t, "p_l_d2", "");
        this.initValue(t, "p_r_d2", "")

        this.initValue(t, "p_l_d3", "");
        this.initValue(t, "p_r_d3", "");

        this.initValue(t, "angle", 90);

        //普通封板面孔参数
        this.initValue(t, "p_l_pos1", this.FormatArrayToPosString(AModelFmulaUtils.getHolesbyExpress(t.p_zkkw, t.L), [(+t.W) - (+t.fjcmjl)]));
        this.initValue(t, "p_r_pos01", this.FormatArrayToPosString(AModelFmulaUtils.getHolesbyExpress(t.p_zkkw, t.L), [(+t.fjcmjl), (+t.W) - (+t.fjcmjl)]));

        //L封板的面孔参数
        this.initValue(t, "p_r_pos1", this.FormatArrayToPosString(AModelFmulaUtils.getHolesbyExpress(t.p_zkkw, t.L), [(+t.W) - (+t.fjcmjl)]));

        this.initValue(t, "p_l_pos2", "");
        this.initValue(t, "p_r_pos2", "");

        this.initValue(t, "p_l_pos3", "");
        this.initValue(t, "p_r_pos3", "");

        //角铝封板
        this.initValue(t, "p_zkkw", t.p_szykw);
        this.initValue(t, "p_ykkw", t.p_szykw);


        //切位

    }

    check(id: any): boolean {
        let code = ~~id + EntityCreateType.modeStart;
        if (code >= EntityCreateType.Shrouding && code <= EntityCreateType.AngleAluminumShrouding) {
            return true;
        }

        return false;
    }

    private initValue(t, key, s) {
        if (t && !t[key]) {
            t[key] = s;
        }
    }

    /** 数组转坐标对(x,y),(x,y)
     * a 数组
    */
    private FormatArrayToPosString(a: Array<number>, x: Array<number>): string {
        let str = "";

        if (a) {
            let end = a.length - 1;
            for (let [i, xx] of x.entries()) {
                for (let [index, y] of a.entries()) {
                    str += this.formatTo(xx, y);

                    if (index < end) {
                        str += ",";
                    }
                }

                if (i < x.length - 1) {
                    str += ",";
                }
            }

        }

        return str;
    }

    private formatTo(x, y): string {
        return "(" + x + "," + y + ")";
    }
}